home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4789 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.5 KB  |  79 lines

  1. Path: gail.ripco.com!mambuhl
  2. From: mambuhl@ripco.com (Martin Ambuhl)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Urgent help needed
  5. Date: 6 Feb 1996 21:39:09 GMT
  6. Organization: Ripco Communications, Inc.
  7. Message-ID: <4f8hpt$s0a@gail.ripco.com>
  8. NNTP-Posting-Host: foley.ripco.com
  9.  
  10. randy@netspace.net.au (Patrick Liang)
  11. in <4f6v8q$ov6@otis.netspace.net.au> asks:
  12.  
  13. >I am doing a program to convert a serial no to date format, the serial no is
  14. >representing the seconds elapsed since 01/01/1970. and I using the Visual basic
  15. >to call the DLL function(general from Borland C++ version 4).
  16.  
  17. Since DLLs and WinDoze questions are implementation-details and not C,
  18. and Visual Basic is not C, I will ignore those aspects of your question.
  19. The following concerns your C code (the original of which is at EOM).
  20.  
  21. Check the differences between the following and your code, and perhaps
  22. you will see something useful.
  23.  
  24. #include <stdlib.h>
  25. #include <time.h>
  26. #include <stdio.h>
  27. #define FAR                     /* mha - added to ignore FAR */
  28. #define PASCAL                  /* mha - added to ignore PASCAL */
  29. char * FAR PASCAL NUMTODATE(char *argv1) /* mha - return type changed
  30.                                  * from "char" to "char *" */
  31. {
  32.     struct tm *ptr;
  33.     char *c /* mha - ", buf1[80]" unused */;
  34.     time_t l;                   /* mha - was "long" */
  35.     l = atol(argv1);            /* mha - (time_t) cast if you want */
  36.     ptr = localtime(&l);        /* mha - localtime takes a time_t arg,
  37.                                  * which is only guaranteed to be an
  38.                                  * arithmetic type capable of
  39.                                  * representing times.  The old
  40.                                  * declaration of "long l;" clearly
  41.                                  * won't do.  */
  42.     c = asctime(ptr);
  43.     puts(c);
  44.     return c;                   /* mha - was "return *c;" */
  45. }
  46.  
  47.  
  48. [ === randy's original C code ===]
  49. >/*  this is the main c program Using Borland C++ */
  50.  
  51. >/* Demonstrates the functions */
  52.  
  53. >#include <stdio.h>
  54. >#include <time.h>
  55. >#include <stdlib.h>
  56. >#include <windows.h>
  57.  
  58.  
  59. >char FAR PASCAL NUMTODATE(char *argv1)
  60. >{
  61.  
  62. >        struct tm *ptr;
  63. >        char *c, buf1[80];
  64. >        long l;
  65.  
  66. >         l = atol(argv1);
  67.  
  68. >         ptr = localtime(&l);
  69.  
  70. >        c = asctime(ptr);
  71. >        puts(c);
  72.  
  73. >        return *c;
  74. >}
  75.                                                                                                           
  76. --
  77. * Martin Ambuhl       net: mambuhl@ripco.com
  78. * Chicago, IL (USA)    
  79.